using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class Extensions
{
    public static Transform GetMin<T>(this Transform[] ts, Func<Transform, T> condition) where T : IComparable
    {
        if (ts.Length == 0) return null;
        Transform result = ts[0];
        foreach (var trans in ts)
        {
            if (condition(result).CompareTo(condition(trans)) == 1)
            {
                result = trans;
            }
        }
        return result;
    }

    public static Transform GetMin<T>(this List<Transform> ts, Func<Transform, T> condition) where T : IComparable
    {
        if (ts.Count == 0) return null;
        Transform result = ts[0];
        foreach (var trans in ts)
        {
            if (condition(result).CompareTo(condition(trans)) == 1)
            {
                result = trans;
            }
        }
        return result;
    }
}
